package cn.wsalix.templet.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.anlaser.service.impl.SimpleServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.wsalix.admin.service.MenuService;
import cn.wsalix.biz.service.ArticleService;
import cn.wsalix.templet.entity.SiteInfo;
import cn.wsalix.templet.entity.SitePagePlace;
import cn.wsalix.templet.entity.SitePlace;
import cn.wsalix.templet.entity.SiteTemplet;
import cn.wsalix.templet.form.SiteTempletForm;
import cn.wsalix.templet.repository.SitePageRepository;
import cn.wsalix.templet.repository.SiteTempletRepository;
import cn.wsalix.templet.service.SiteTempletService;

@Service("siteTempletService")
@Transactional(readOnly = true)
public class SiteTempletServiceImpl extends
		SimpleServiceImpl<SiteTempletForm,SiteTempletRepository, SiteTemplet> implements
		SiteTempletService {

	@Autowired
	private SiteTempletRepository siteTempletRepository;
	
	@Autowired
	private SitePageRepository sitePageRepository;
	@Autowired
	private ArticleService articleService;
	@Autowired
	private MenuService menuService;

	@Override
	public SiteTempletRepository getRepository() {
		return siteTempletRepository;
	}

	@Override
	public String module() {
		return "sitetemplet";
	}

	@Override
	public SiteTemplet findByTempletCode(String templetCode) {
		return siteTempletRepository.findByTempletCodeOne(templetCode);
	}

	public Set<Entry<String, Object>> treatPage(
			List<SitePagePlace> sitePagePlace) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		for (SitePagePlace pagePlace : sitePagePlace) {
			/*SitePlace sitePlace = pagePlace.getSitePlace();
			if (sitePlace.getPageData() == null) {
				continue;
			}*/
			/*switch (sitePlace.getPageDate()) {
			case SINGLE_ARTICLE:
				Article article = articleService.findById(sitePlace
						.getParaValue());
				resMap.put("singleArt", article);
				break;
			case CATORY_ARTICLE:
				List<Article> articles = articleService
						.findByCatoryId(sitePlace.getParaValue());
				resMap.put("articles", articles);
				break;
			case SINGLE_MENU:
				SysMenu singleMenu = menuService.findById(sitePlace
						.getParaValue());
				resMap.put("singleMenu", singleMenu);
				break;
			case CATORY_MENU:
				List<SysMenu> catoryMenus = menuService
						.findByParentId(sitePlace.getParaValue());
				resMap.put("catoryMenus", catoryMenus);
				break;
			case ADMIN_MENUS:
				List<SysMenu> adminMenus = menuService.findAll();				
				resMap.put("menus", adminMenus);
				break;
			default:
				break;

			}*/
		}
		return resMap.entrySet();
	}
/*
	public SiteTemplet findBySite(SiteInfo siteInfo) {
		return siteTempletRepository.findBySiteId(siteInfo.getId());
	}
*/
	@Override
	public Class<SiteTemplet> getEntityClazz() {
		// TODO Auto-generated method stub
		return SiteTemplet.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(SiteTempletForm form) {
		// TODO Auto-generated method stub
		return null;
	}

}
